// 获取当前日期
var currentDate = new Date();

// 获取昨天的日期
var yesterday = new Date(currentDate);
yesterday.setDate(currentDate.getDate() - 1);

// 格式化日期
var formattedDate = yesterday.getFullYear() + "-" + 
                    ("0" + (yesterday.getMonth() + 1)).slice(-2) + "-" + 
                    ("0" + yesterday.getDate()).slice(-2) + " " + 
                    "00:00:00";

// 获取昨天的结束时间
var formattedEndTime = yesterday.getFullYear() + "-" + 
                       ("0" + (yesterday.getMonth() + 1)).slice(-2) + "-" + 
                       ("0" + yesterday.getDate()).slice(-2) + " " + 
                       "23:59:59";

// 打印结果  昨天的时间范围是：2024-05-26 00:00:00 到 2024-05-26 23:59:59
console.log("昨天的时间范围是：" + formattedDate + " 到 " + formattedEndTime);